package com.lzw.mall.common.service.impl;

import com.lzw.mall.common.entity.Member;
import com.lzw.mall.common.vo.OrderSessionUtil;
import com.lzw.mall.common.vo.ResultVO;
import com.lzw.mall.common.entity.MemberAddress;
import com.lzw.mall.common.mapper.MemberAddressMapper;
import com.lzw.mall.common.service.IMemberAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lizhenwei
 * @since 2023-04-07
 */
@Service
public class MemberAddressServiceImpl extends ServiceImpl<MemberAddressMapper, MemberAddress> implements IMemberAddressService {

    @Autowired
    private MemberAddressMapper memberAddressMapper;

    @Override
    public List<MemberAddress> selectByMemberId(Integer id) {
        return memberAddressMapper.selectByMemberId(id);
    }

    @Override
    public void delMemberAddress(Integer id, Integer id1) {
        memberAddressMapper.delMemberAddress(id,id1);
    }

    @Override
    public void updataMemberAddressDefaultAddr(Integer id) {
        Member m= OrderSessionUtil.getCurrent();
        memberAddressMapper.updataMemberAddressDefaultAddrSet1(m.getId());
        memberAddressMapper.updataMemberAddressDefaultAddr(id);
    }

    @Override
    public List<MemberAddress> selectMemberAddress() {
        List<MemberAddress> list = null;
        Member m=OrderSessionUtil.getCurrent();
        list=memberAddressMapper.selectMemberAddress(m.getId());
        return list;
    }

    @Override
    public ResultVO selMemberAddress(Integer id) {
        ResultVO vo = new ResultVO();
        vo.setData(baseMapper.selMemberAddressById(id));
        return vo;
    }

    @Override
    public void updataMemberAddressById(MemberAddress memberAddress) {
        baseMapper.updateById(memberAddress);
    }
}
